//
//  ServiceItemView.m
//  MexicoLoan
//
//  Created by WXP on 2025/3/7.
//
//

#import "ServiceItemView.h"

@interface ServiceItemView ()

@end

@implementation ServiceItemView

#pragma mark - lazy
- (UIImageView *)imageMark{
    if (_imageMark == nil) {
        _imageMark = [UIImageView new];
        _imageMark.widthHeight = XY(18, 18);
    }
    return _imageMark;
}
- (UILabel *)labelTitle{
    if (_labelTitle == nil) {
        _labelTitle = [UILabel new];
        _labelTitle.textColor = COLOR_BLACK;
        _labelTitle.fontNum = 12;
        
    }
    return _labelTitle;
}
- (UILabel *)labelContent{
    if (_labelContent == nil) {
        _labelContent = [UILabel new];
        _labelContent.textColor = COLOR_BLACK;
        _labelContent.font = [UIFont boldSystemFontOfSize:18];
        _labelContent.numberOfLines = 0;
        _labelContent.lineSpace = 2; 
    }
    return _labelContent;
}
- (UIView *)lineView{
    if (_lineView == nil) {
        _lineView = [UIView new];
        _lineView.backgroundColor = COLOR_LINE;
    }
    return _lineView;
}

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.width = SCREEN_WIDTH-2*LEFT_MARDIN;
        [self addSubView];
        UITapGestureRecognizer * tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
        [self addGestureRecognizer:tapGestureRecognizer];
    }
    return self;
}

//添加subview
- (void)addSubView{
    [self addSubview:self.imageMark];
    [self addSubview:self.labelTitle];
    [self addSubview:self.labelContent];
    [self addSubview:self.lineView];
}

#pragma mark - 手势点击
- (void)tapClick:(UITapGestureRecognizer * )tap{
    [NSObject clickFeedback];
    if(self.blockItemClick){
        self.blockItemClick();
    }
}

#pragma mark - 刷新view
- (void)resetViewWithModel:(ModelBtn *)model{
    self.imageMark.leftTop = XY(20, 30);
    self.imageMark.image = [UIImage imageNamed:model.imageName];
    
    [self.labelTitle fitTitle:readStr(model.title) variable:self.width-self.imageMark.left-self.imageMark.right-10];
    self.labelTitle.leftCenterY = XY(self.imageMark.right+10, self.imageMark.centerY);
    
    self.labelContent.width = self.width-self.imageMark.left-self.imageMark.right-10;
    NSString * str = [NSString stringWithFormat:@"%@  ",readStr(model.content)];
    [self.labelContent setAttributedText:[str setImageName:model.highImageName imageRect:CGRectMake(0, -3, 16, 16) withIndex:str.length]];
    [self.labelContent sizeToFit];
    self.labelContent.leftTop = XY(self.labelTitle.left, self.labelTitle.bottom+20);
    
    self.lineView.widthHeight = XY(self.width-self.imageMark.left-self.labelTitle.left, 1);
    self.lineView.leftTop = XY(self.labelTitle.left, self.labelContent.bottom+15);
    
    self.height = self.lineView.bottom+15;
}




@end
